﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace FeedAntGame.Sprite
{
    class LoadingTextSprite : BaseSprite
    {
        int delayTime = 0;

        /// <summary>
        /// scale: miliseconds
        /// </summary>
        public int DelayTime
        {
            get { return delayTime; }
            set { delayTime = value; }
        }

        public LoadingTextSprite(Texture2D textureImage, Vector2 position, Point frameSize,
            int collisionOffset, Point currentFrame, Point sheetSize, Vector2 speed, string collisionCueName,
            float scale)
            : base(textureImage, position, frameSize, collisionOffset, currentFrame,
            sheetSize, speed, collisionCueName, 0, scale)
        {
            this.color = Color.FromNonPremultiplied(2, 2, 2, 2);
        }

        public LoadingTextSprite(Texture2D textureImage, Vector2 position, Point frameSize,
            int collisionOffset, Point currentFrame, Point sheetSize, Vector2 speed,
            int millisecondsPerFrame, string collisionCueName, float scale)
            : base(textureImage, position, frameSize, collisionOffset, currentFrame,
            sheetSize, speed, millisecondsPerFrame, collisionCueName, 0, scale)
        {
            this.color = Color.FromNonPremultiplied(2, 2, 2, 2);
        }

        public override Vector2 Direction
        {
            get { return speed; }
        }

        private int mout = 2; // >=0
        public override void Update(GameTime gameTime, Rectangle clientBounds)
        {
            
            if (this.IsLive)
            {
                Position += Direction;
                //if (gameTime.ElapsedGameTime.Seconds>100)

                if (this.color.A <= 0 || this.color.A >= 255 - this.mout)
                {
                    mout *= -1;
                }
                this.color.A += (byte)mout;
                this.color.R += (byte)mout;
                this.color.G += (byte)mout;
                this.color.B += (byte)mout;
            }
            
            if (color.A == 0)
            {
                this.IsLive = false;
                this.color = Color.FromNonPremultiplied(0,0,0,0);
                mout *= -1;
            }
            base.Update(gameTime, clientBounds);
        }

        public bool delay(int miliseconds)
        {
            bool ret = false;
            delayTime -= miliseconds;
            if (delayTime <= 0)
            {
                ret = true;
            }
            return ret;
        }
    }
}
